﻿using System;
using System.IO;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Transliterator.Tests
{
    [TestClass]
    //[DeploymentItem("Modules/Test/Localization/sr-Latn-RS/orchard.module.po", "Modules/Test/Localization/sr-Latn-RS/orchard.module.po")]
    public class PoFileProcesorTest
    {
        private string InputPath = "Modules\\Test\\Localization\\sr-Latn-RS\\orchard.module.po";
        private string OutputPath = "Modules\\Test\\Localization\\sr-Cyrl-RS\\orchard.module.po";

        private PoFileProcesor _poFile;
        private ITransliterator _transliterator;

        [TestInitialize]
        public void TestInitialize()
        {
            InputPath = AppDomain.CurrentDomain.BaseDirectory + "\\" + InputPath;
            OutputPath = AppDomain.CurrentDomain.BaseDirectory + "\\" + OutputPath;

            DeleteOutputFiles();

            _transliterator = new Transliterator();
            _poFile = new PoFileProcesor(_transliterator, InputPath);
        }

        [TestCleanup]
        public void TestCleanup()
        {
            _poFile = null;
            DeleteOutputFiles();
        }

        [TestMethod]
        public void LoadTestFile()
        {
            Assert.IsNotNull(_poFile);
        }

        [TestMethod]
        public void TransliterateSingleMsgStrLineUsingRegEx()
        {
            const string input = "msgstr \"abcdefgh\"";
            const string expected = "abcdefgh";

            var regex = new Regex("msgstr \"(.*)\"", RegexOptions.Singleline);

            Assert.AreEqual(expected, regex.Match(input).Groups[1].Value);


        }


        [TestMethod]
        public void CopyResultToSrCyrlRsFolder()
        {
            _poFile.Transliterate();
            Assert.IsTrue(File.Exists(OutputPath));
        }



        private void DeleteOutputFiles()
        {
            if (File.Exists(OutputPath))
                File.Delete(OutputPath);
        }

    }
}